import { createWebHistory, createRouter } from 'vue-router'
/* Layout */
import Layout from '@/layout'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: '/:pathMatch(.*)*',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  // {
  //   name: 'Statement',
  //   path: '/statement/warehouses-kb',
  //   hidden: true,
  //   component: () => import('@/views/statement/warehouse/index.vue'),
  //   meta: {
  //     title: '仓库看板',
  //     icon: 'qudaoguanli',
  //     noCache: false,
  //     link: null
  //   }
  // },
  {
    name: 'Qualitys',
    path: '/statement/qualitys',
    hidden: true,
    component: () => import('@/views/statement/quality/index.vue'),
    meta: {
      title: '品质看板',
      icon: 'qiyeguanli',
      noCache: false,
      link: null
    }
  },
  {
    name: 'warehouses',
    path: '/statement/warehouses-kb',
    hidden: true,
    component: () => import('@/views/statement/warehouse/index.vue'),
    meta: {
      title: '仓库看板',
      icon: 'qiyeguanli',
      noCache: false,
      link: null
    }
  },
  {
    name: 'Production',
    path: '/statement/production',
    hidden: true,
    component: () => import('@/views/statement/production/index.vue'),
    meta: {
      title: '生产看板',
      icon: 'shujubaobiao',
      noCache: false,
      link: null
    }
  },
  {
    path: '',
    component: Layout,
    redirect: '/layout',
    children: [
      {
        path: '/layout',
        component: () => import('@/views/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: () => import('@/views/system/user/profile/index'),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user' }
      }
    ]
  }
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: '/system/user-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:user:edit'],
    children: [
      {
        path: 'role/:userId(\\d+)',
        component: () => import('@/views/system/user/authRole'),
        name: 'AuthRole',
        meta: { title: '分配角色', activeMenu: '/system/user' }
      }
    ]
  },
  {
    path: '/system/role-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:role:edit'],
    children: [
      {
        path: 'user/:roleId(\\d+)',
        component: () => import('@/views/system/role/authUser'),
        name: 'AuthUser',
        meta: { title: '分配用户', activeMenu: '/system/role' }
      }
    ]
  },

  {
    path: '/monitor/job-log',
    component: Layout,
    hidden: true,
    permissions: ['monitor:job:list'],
    children: [
      {
        path: 'index',
        component: () => import('@/views/monitor/job/log'),
        name: 'JobLog',
        meta: { title: '调度日志', activeMenu: '/monitor/job' }
      }
    ]
  },
  {
    path: '/tool/gen-edit',
    component: Layout,
    hidden: true,
    permissions: ['tool:gen:edit'],
    children: [
      {
        path: 'index/:tableId(\\d+)',
        component: () => import('@/views/tool/gen/editTable'),
        name: 'GenEdit',
        meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
      }
    ]
  },
  {
    path: '/system/dict-data',
    component: Layout,
    hidden: true,
    permissions: ['system:dict:list'],
    children: [
      {
        path: 'index/:dictId(\\d+)',
        component: () => import('@/views/system/dict/data'),
        name: 'Data',
        meta: { title: '字典数据', activeMenu: '/system/dict' }
      }
    ]
  },

  // {
  //   path: '/material/bom/edtail',
  //   component: Layout,
  //   hidden: true,
  //   permissions: ['material:bom:list'],
  //   children: [
  //     {
  //       path: '/material/bom/edtail',
  //       component: () => import('@/views/material/bom/edtail'),
  //       name: 'Baom',
  //       meta: { title: 'BOM详情', activeMenu: '/material/bom' }
  //     }
  //   ]
  // },
  {
    path: '/order/subcontracting/order-data',
    component: Layout,
    hidden: true,
    permissions: ['order:subcontracting:order:list'],
    children: [
      {
        path: '/order/subcontracting/order-data',
        component: () => import('@/views/order/subcontracting/order/details'),
        name: 'Details',
        meta: { title: '订单详情', activeMenu: 'order/subcontracting/order/index' }
      }
    ]
  },
  // 生产条件 配比
  {
    path: '/schedule/scheduleConfig/condition-pb',
    component: Layout,
    hidden: true,
    permissions: ['schedule:scheduleConfig:condition:list'],
    children: [
      {
        path: 'index/:id(\\d+)',
        component: () => import('@/views/schedule/scheduleConfig/condition/pb'),
        name: 'Configs',
        meta: { title: '排程条件配置', activeMenu: '/schedule/scheduleConfig/condition' }
      }
    ]
  },
  // 生产排程 详情
  {
    path: '/schedule/plan/productionSchedule-data',
    component: Layout,
    hidden: true,
    permissions: ['schedule:plan:productionSchedule:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/schedule/plan/productionSchedule/details'),
        name: 'productionSchedule',
        meta: { title: '生产排程详情', activeMenu: '/schedule/plan/productionSchedule' }
      }
    ]
  },
  // 仓储模块
  {
    path: '/warehouse/warehousing/purchase-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:warehousing:purchase:list'],
    children: [
      {
        path: 'index/:id(\\d+)',
        component: () => import('@/views/warehouse/warehousing/purchase/details'),
        name: 'purchase-data',
        meta: { title: '入库明细', activeMenu: '/warehouse/warehousing/purchase' }
      }
    ]
  },
  // 仓储模块 调拨管理订单
  {
    path: '/warehouse/inside/transfer-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:inside:transfer:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/warehouse/inside/transfer/data'),
        name: 'transfer-data',
        meta: { title: '调拨明细', activeMenu: '/warehouse/inside/transfer' }
      }
    ]
  },

  // 出库 生产领料
  {
    path: '/warehouse/outbound/producfield-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:outbound:producfield:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/warehouse/outbound/producfield/data'),
        name: 'producfield-data',
        meta: { title: '生产领料-出库明细', activeMenu: '/warehouse/outbound/producfield' }
      }
    ]
  },
  // 出库 委外发货 出库明细
  {
    path: '/warehouse/outbound/subcontract-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:outbound:subcontract:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/warehouse/outbound/subcontract/data'),
        name: 'subcontract-data',
        meta: { title: '委外发货-出库明细', activeMenu: '/warehouse/outbound/subcontract' }
      }
    ]
  },

  // 制造下 班组管理
  {
    path: '/productionTube/shopAdministration/team-data',
    component: Layout,
    hidden: true,
    permissions: ['productionTube:shopAdministration:team:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/productionTube/shopAdministration/team/details'),
        name: 'team-data',
        meta: { title: '班组管理-班组明细', activeMenu: '/productionTube/shopAdministration/team' }
      }
    ]
  },

  // 分切制令单下 单据明细
  {
    path: '/productionTube/produAdm/slitting/prepara',
    component: Layout,
    hidden: true,
    // permissions: ['productionTube:shopAdministration:team:list'],
    children: [
      {
        path: 'index/:id(\\d+)',
        component: () => import('@/views/productionTube/produAdm/slitting/prepara/uptab'),
        name: 'team-data',
        meta: { title: '分切制令单-单据明细', activeMenu: '/productionTube/produAdm/slitting' }
      }
    ]
  },
  // 水刺产出 生产明细
  {
    path: '/productionTube/produAdm/spunlace/spunproduc-data',
    component: Layout,
    hidden: true,
    permissions: ['productionTube:produAdm:spunlace:spunproduc:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/productionTube/produAdm/spunlace/spunproduc/data'),
        name: 'spunproduc-data',
        meta: { title: '水刺产出-生产明细', activeMenu: '/productionTube/produAdm/spunlace/spunproduc' }
      }
    ]
  },
  // 脱脂产出 生产明细
  {
    path: '/productionTube/produAdm/degrproduc/degparaorder-data',
    component: Layout,
    hidden: true,
    permissions: ['productionTube:produAdm:degrproduc:degparaorder:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/productionTube/produAdm/degrproduc/degparaorder/data'),
        name: 'degparaorder-data',
        meta: { title: '脱脂产出-生产明细', activeMenu: '/productionTube/produAdm/degrproduc/degparaorder' }
      }
    ]
  },
  // 制造下 投料记录-投料明细
  {
    path: '/productionTube/prostatistics/feeding-data',
    component: Layout,
    hidden: true,
    permissions: ['productionTube:prostatistics:feeding:degparaorder:list'],
    children: [
      {
        path: 'index/:id(\\d+)',
        component: () => import('@/views/productionTube/prostatistics/feeding/data'),
        name: 'feeding-data',
        meta: { title: '投料记录-投料明细', activeMenu: '/productionTube/prostatistics/feeding' }
      }
    ]
  },
  // 质量下 检验方案配置详情
  {
    path: '/quality/verifyconfig/inspecscheme/inspecscheme-data',
    component: Layout,
    hidden: true,
    permissions: ['quality:verifyconfig:inspecscheme:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/quality/verifyconfig/inspecscheme/data.vue'),
        name: 'inspecscheme-data',
        meta: { title: '检验方案配置-物料明细', activeMenu: '/quality/verifyconfig/inspecscheme/inspecscheme' }
      }
    ]
  },
  // 制造下 分切制令单明细
  {
    path: '/productionTube/produAdm/slitting/prepara-data',
    component: Layout,
    hidden: true,
    permissions: ['productionTube:produAdm:slitting:prepara:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/productionTube/produAdm/slitting/prepara/data.vue'),
        name: 'prepara-data',
        meta: { title: '分切制令单-单据明细', activeMenu: '/productionTube/produAdm/slitting/prepara' }
      }
    ]
  },
  // 制造下 验布明细
  {
    path: '/productionTube/produAdm/slitting/clothinspec-data',
    component: Layout,
    hidden: true,
    permissions: ['productionTube:produAdm:slitting:clothinspec:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/productionTube/produAdm/slitting/clothinspec/data.vue'),
        name: 'clothinspec-data',
        meta: { title: '验布-明细', activeMenu: '/productionTube/produAdm/slitting/clothinspec' }
      }
    ]
  },
  // 制造下 成品称重 物料明细
  {
    path: '/productionTube/produAdm/slitting/produweight-data',
    component: Layout,
    hidden: true,
    permissions: ['productionTube:produAdm:slitting:produweight:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/productionTube/produAdm/slitting/produweight/data.vue'),
        name: 'produweight-data',
        meta: { title: '成品称重-物料明细', activeMenu: '/productionTube/produAdm/slitting/produweight' }
      }
    ]
  },
  // 制造下 成品称重 单据明细
  {
    path: '/productionTube/produAdm/slitting/produweight-dataTwo',
    component: Layout,
    hidden: true,
    permissions: ['productionTube:produAdm:slitting:produweight:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/productionTube/produAdm/slitting/produweight/dataTwo.vue'),
        name: 'produweight-dataTwo',
        meta: { title: '成品称重-单据明细', activeMenu: '/productionTube/produAdm/slitting/produweight' }
      }
    ]
  },
  // 仓储 入库管理 销售退货 入库明细
  {
    path: '/warehouse/warehousing/saleReturn-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:warehousing:saleReturn:list'],
    children: [
      {
        path: 'index/:id(\\d+)',
        component: () => import('@/views/warehouse/warehousing/saleReturn/data.vue'),
        name: 'saleReturn-data',
        meta: { title: '销售退货-入库明细', activeMenu: '/warehouse/warehousing/saleReturn' }
      }
    ]
  },
  // 仓储 入库管理 生产退料 入库明细
  {
    path: '/warehouse/warehousing/productionReturn-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:warehousing:productionReturn:list'],
    children: [
      {
        path: 'index/:id(\\d+)',
        component: () => import('@/views/warehouse/warehousing/productionReturn/data.vue'),
        name: 'productionReturn-data',
        meta: { title: '生产退料-入库明细', activeMenu: '/warehouse/warehousing/productionReturn' }
      }
    ]
  },
  // 仓储 入库管理 完工入库 入库明细
  {
    path: '/warehouse/warehousing/finished-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:warehousing:finished:list'],
    children: [
      {
        path: 'index/:id(\\d+)',
        component: () => import('@/views/warehouse/warehousing/finished/data.vue'),
        name: 'finished-data',
        meta: { title: '完工入库明细', activeMenu: '/warehouse/warehousing/finished' }
      }
    ]
  },
  // 仓储 入库管理 其他入库 入库明细
  {
    path: '/warehouse/warehousing/other-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:warehousing:other:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/warehouse/warehousing/other/data.vue'),
        name: 'other-data',
        meta: { title: '其他入库-明细', activeMenu: '/warehouse/warehousing/other' }
      }
    ]
  },
  // 仓储 入库管理 委外入库 入库明细
  {
    path: '/warehouse/warehousing/subcontracting-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:warehousing:subcontracting:list'],
    children: [
      {
        path: 'index/:id(\\d+)',
        component: () => import('@/views/warehouse/warehousing/subcontracting/data.vue'),
        name: 'subcontracting-data',
        meta: { title: '委外入库-明细', activeMenu: '/warehouse/warehousing/subcontracting' }
      }
    ]
  },

  // 出库 销售发货
  {
    path: '/warehouse/outbound/shipsale-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:outbound:shipsale:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/warehouse/outbound/shipsale/data'),
        name: 'shipsale-data',
        meta: { title: '销售发货-出库明细', activeMenu: '/warehouse/outbound/shipsale' }
      }
    ]
  },

  // 出库 返工出库
  {
    path: '/warehouse/outbound/reworksto-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:outbound:reworksto:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/warehouse/outbound/reworksto/data'),
        name: 'reworksto-data',
        meta: { title: '返工出库-出库明细', activeMenu: '/warehouse/outbound/reworksto' }
      }
    ]
  },

  // 出库 采购退货
  {
    path: '/warehouse/outbound/purreturn-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:outbound:purreturn:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/warehouse/outbound/purreturn/data'),
        name: 'purreturn-data',
        meta: { title: '采购退货-出库明细', activeMenu: '/warehouse/outbound/purreturn' }
      }
    ]
  },

  // 出库 委外退货
  {
    path: '/warehouse/outbound/subcontout-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:outbound:subcontout:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/warehouse/outbound/subcontout/data.vue'),
        name: 'subcontout-data',
        meta: { title: '委外退货-出库明细', activeMenu: '/warehouse/outbound/subcontout' }
      }
    ]
  },

  // 出库 其他出库
  {
    path: '/warehouse/outbound/otherout-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:outbound:otherout:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/warehouse/outbound/otherout/data.vue'),
        name: 'otherout-data',
        meta: { title: '其他出库-出库明细', activeMenu: '/warehouse/outbound/otherout' }
      }
    ]
  },
  // 来料打印 打印明细
  {
    path: '/warehouse/incomingPrint/print-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:incomingPrint:print:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/warehouse/incomingPrint/print/data.vue'),
        name: 'print-data',
        meta: { title: '采购打印-打印明细', activeMenu: '/warehouse/incomingPrint/print' }
      }
    ]
  },

  // 来料打印 打印明细
  {
    path: '/warehouse/incomingPrint/weiwaiPrint-data',
    component: Layout,
    hidden: true,
    permissions: ['warehouse:incomingPrint:print:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/warehouse/incomingPrint/print/data2.vue'),
        name: 'weiwaiPrint-data',
        meta: { title: '委外打印-打印明细', activeMenu: '/warehouse/incomingPrint/print' }
      }
    ]
  },
  // 配置字段
  {
    path: '/system/printConfig-data',
    component: Layout,
    hidden: true,
    permissions: ['system:printConfig:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/system/printConfig/fieldConfig.vue'),
        name: 'printConfig-data',
        meta: { title: '字段配置', activeMenu: '/system/printConfig' }
      }
    ]
  },

  // 配置内容
  {
    path: '/system/printConfig-print',
    component: Layout,
    hidden: true,
    permissions: ['system:printConfig:list'],
    children: [
      {
        path: '',
        component: () => import('@/views/system/printConfig/print.vue'),
        name: 'printConfig-print',
        meta: { title: '配置内容', activeMenu: '/system/printConfig' }
      }
    ]
  },

  // 生产计划报表-领投料明细
  {
    path: '/traceback/producPlanReport-data',
    component: Layout,
    hidden: true,
    permissions: ['traceback:producPlanReport:list'],
    children: [
      {
        path: 'index/:id(\\d+)',
        component: () => import('@/views/traceback/producPlanReport/data.vue'),
        name: 'dipWorkshop-data',
        meta: { title: '领投料明细', activeMenu: '/traceback/producPlanReport' }
      }
    ]
  },

  // 生产计划报表-完工明细
  {
    path: '/traceback/producPlanReport-detail',
    component: Layout,
    hidden: true,
    permissions: ['traceback:producPlanReport:list'],
    children: [
      {
        path: 'index/:id(\\d+)',
        component: () => import('@/views/traceback/producPlanReport/detail.vue'),
        name: 'dipWorkshop-detail',
        meta: { title: '完工明细', activeMenu: '/traceback/producPlanReport' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  // mode: 'hash',
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router
